//
//  Person.m
//  05 - 作业
//
//  Created by 韩旭 on 16/7/8.
//  Copyright © 2016年 基础. All rights reserved.
//

#import "Person.h"

@implementation Person

- (instancetype)initWithName:(NSString *)name Age:(NSInteger)age Sex:(NSString *)sex {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _sex = sex;
    }
    return self;
}
- (NSString *)description {
    return [NSString stringWithFormat:@"name = %@, age = %ld, sex = %@", _name, _age, _sex];
}

- (NSComparisonResult)compareAge:(Person *)person {
    if (_age < person.age) {
        return NSOrderedAscending;//升序
    } else if (_age == person.age) {
        return NSOrderedSame;//
    } else {
        return NSOrderedDescending;
    }
}
- (NSComparisonResult)compareName:(Person *)person {
    return [self.name compare:person.name];
}

@end
